#encoding=utf-8
'''
Created on 2014-12-9

@author: cooler
'''
import sys, logging, os, os.path
sys.path.append(os.getcwd()+"/service" )
sys.path.append(os.getcwd()+"/utils" )

from Config import initConfig
config = initConfig()

from flask import Flask
#------------app interface-------------------
from home import home


from model import *
import random

DEFAULT_APP_NAME = 'SUFACE'


DEFAULT_MODULES = (
            (home, '/home'),
)

# def create_app():
#     """ 创建、初始化app """
#     app = Flask(DEFAULT_APP_NAME)
#     # 使用flask中的Blueprint设置站点模块
#     setting_modules(app, DEFAULT_MODULES)
#     read_num_start = int(config.get("mysql","read_num_start"))
#     read_num_end = int(config.get("mysql","read_num_end"))
#     read_num = str(random.randint(read_num_start,read_num_end))
#     host = config.get("mysql","host_secondary"+str(read_num))
#     port = int(config.get("mysql","port_secondary"+str(read_num)))
#     username = config.get("mysql","username_secondary"+str(read_num))
#     password = config.get("mysql","password_secondary"+str(read_num))
#     dbname = config.get("mysql","dbname_secondary"+str(read_num))
#     app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://'+username+':'+password+'@'+host+':3306/'+dbname+'?charset=utf8'
#     app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
#     app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
#     app.config['SQLALCHEMY_POOL_SIZE'] = 200
#     mdb_read.init_app(app)
#     host = config.get("mysql","host_primary")
#     port = int(config.get("mysql","port_primary"))
#     username = config.get("mysql","username_primary")
#     password = config.get("mysql","password_primary")
#     dbname = config.get("mysql","dbname_primary")
#     app.config['SQLALCHEMY_ART_DATABASE_URI'] = 'mysql://'+username+':'+password+'@'+host+':3306/'+dbname+'?charset=utf8'
#     app.config['SQLALCHEMY_ART_COMMIT_ON_TEARDOWN'] = True
#     app.config['SQLALCHEMY_ART_POOL_SIZE'] = 100
#     mdb_write.init_app(app)
#     return app

def setting_modules(app, modules):
    """ 注册Blueprint模块 """
    for module, url_prefix in modules:
	    # 通过register_blueprint注册
	    app.register_blueprint(module, url_prefix = url_prefix)

        